import FonctionSetCover as F
import Producteur as P
import Set as S
import Consommateur as C


TabClient=[]
TabProd=[]
TabProd.append(P.Producteur("P1","Rhone-Alpes",45,5,30.9,1122612,0,10))
TabProd.append(P.Producteur("P2","Centre",47,1,30.9,979534,0,10))
TabProd.append(P.Producteur("P3","Haute-Normandie",49,0,30.9,665863,0,10))
TabProd.append(P.Producteur("P4","Champagne-Ardenne",48,4,30.9,5090275,0,10))
TabProd.append(P.Producteur("P5","Nord-Pas-de-Calais",50,2,30.9,4925185,0,10))
TabProd.append(P.Producteur("P6","Lorraine",48,6,30.9,467755,0,10))
TabProd.append(P.Producteur("P7","Ile-de-France",46,2,30.9,126569,0,10))
TabProd.append(P.Producteur("P8","Ile-de-France",46,2,30.9,126569,0,10))
TabProd.append(P.Producteur("P9","Provence-Alpes-Cote-d'Azur",46,2,30.9,126569,0,10))
TabProd.append(P.Producteur("P10","Midi-Pyrenees",46,2,30.9,126569,0,10))
TabProd.append(P.Producteur("P11","Champagne-Ardenne",46,2,30.9,126569,0,10))
TabProd.append(P.Producteur("P12","Haute-Normandie",46,2,30.9,126569,0,10))
TabProd.append(P.Producteur("P13","Bourgogne",46,2,30.9,126569,0,10))
TabProd.append(P.Producteur("P14","Pays de la Loire",46,2,30.9,126569,0,10))
TabProd.append(P.Producteur("P15","La Reunion",46,2,30.9,126569,0,10))
TabProd.append(P.Producteur("P16","Bretagne",46,2,30.9,126569,0,10))
TabProd.append(P.Producteur("P17","Languedoc-Roussillon",46,2,30.9,126569,0,10))
TabProd.append(P.Producteur("P18","Limousin",46,2,30.9,126569,0,10))
TabProd.append(P.Producteur("P19","Auvergne",46,2,30.9,126569,0,10))
TabProd.append(P.Producteur("P20","Picardie",46,2,30.9,126569,0,10))
TabProd.append(P.Producteur("P21","Lorraine",46,2,30.9,126569,0,10))
TabProd.append(P.Producteur("P22","Franche-Comte",46,2,30.9,126569,0,10))
TabProd.append(P.Producteur("P23","Alsace",46,2,30.9,126569,0,10))
TabProd.append(P.Producteur("P24","Basse-Normandie",46,2,30.9,126569,0,10))
TabProd.append(P.Producteur("P25","Poitou-Charentes",46,2,30.9,126569,0,10))
TabProd.append(P.Producteur("P26","Martinique",46,2,30.9,126569,0,10))
TabProd.append(P.Producteur("P27","Aquitaine",46,2,30.9,126569,0,10))
TabProd.append(P.Producteur("P28","Corse",46,2,30.9,126569,0,10))
TabProd.append(P.Producteur("P29","Guadeloupe",46,2,30.9,126569,0,10))
TabProd.append(P.Producteur("P30","Guyane francaise",46,2,30.9,126569,0,10))
TabProd.append(P.Producteur("P31","Corse",46,2,30.9,126569,0,10))
TabProd.append(P.Producteur("P32","Corse",46,2,30.9,126569,0,10))
TabProd.append(P.Producteur("P33","Corse",46,2,30.9,126569,0,10))



TabClient.append(C.Consommateur(48,2,"Paris","Ile-de-France",22234105,1667557875))
TabClient.append(C.Consommateur(43,5,"Marseille","Provence-Alpes-Cote d'Azur",850602,63795150))
TabClient.append(C.Consommateur(45, 4,"Lyon","Rhone-Alpes",479803,35985225))
TabClient.append(C.Consommateur(43, 1,"Toulouse","Midi-Pyrenees",440204,33015300))
TabClient.append(C.Consommateur(43, 7,"Nice","Provence-Alpes-Cote d'Azur",340735,25555125))
TabClient.append(C.Consommateur(47, -1,"Nantes","Pays de la Loire",282047,21153525))
TabClient.append(C.Consommateur(48, 7,"Strasbourg","Alsace",271708,20378100))
TabClient.append(C.Consommateur(43, 3,"Montpellier","Languedoc-Roussillon",255080,19131000))
TabClient.append(C.Consommateur(44, 0,"Bordeaux","Aquitaine",236725,17754375))
TabClient.append(C.Consommateur(50, 3,"Lille","Nord-Pas-de-Calais",226827,17012025))
TabClient.append(C.Consommateur(48, 1,"Rennes","Bretagne",206604,15495300))
TabClient.append(C.Consommateur(49, 4,"Reims","Champagne-Ardenne",180842,13563150))
TabClient.append(C.Consommateur(49, 0,"Le Havre","Haute-Normandie",177259,13294425))
TabClient.append(C.Consommateur(45, 4,"Saint-Etienne","Rhone-Alpes",171961,12897075))
TabClient.append(C.Consommateur(43, 5,"Toulon","Provence-Alpes-Cote d'Azur",165514,12413550))
TabClient.append(C.Consommateur(45, 5,"Grenoble","Rhone-Alpes",155632,11672400))
TabClient.append(C.Consommateur(47, 5,"Dijon","Bourgogne",152110,11408250))
TabClient.append(C.Consommateur(47, 0,"Angers","Pays de la Loire",147305,11047875))
TabClient.append(C.Consommateur(0,-20.55,"Saint-Denis","La Reunion",145209,10890675))
TabClient.append(C.Consommateur(45, 4,"Villeurbanne","Rhone-Alpes",144751,10856325))
TabClient.append(C.Consommateur(48, 0,"Le Mans","Pays de la Loire",142281,10671075))
TabClient.append(C.Consommateur(43, 5,"Aix-en-Provence","Provence-Alpes-Cote d'Azur",141895,10642125))
TabClient.append(C.Consommateur(48, -4,"Brest","Bretagne",141315,10598625))
TabClient.append(C.Consommateur(43, 4,"Nimes","Languedoc-Roussillon",140747,10556025))
TabClient.append(C.Consommateur(45, 1,"Limoges","Limousin",139216,10441200))
TabClient.append(C.Consommateur(45, 3,"Clermont-Ferrand","Auvergne",138588,10394100))
TabClient.append(C.Consommateur(47, 0,"Tours","Centre",135218,10141350))
TabClient.append(C.Consommateur(49, 2,"Amiens","Picardie",133998,10049850))
TabClient.append(C.Consommateur(49, 6,"Metz","Lorraine",121841,9138075))
TabClient.append(C.Consommateur(42, 2,"Perpignan","Languedoc-Roussillon",117905,8842875))
TabClient.append(C.Consommateur(47, 6,"Besancon","Franche-Comte",117392,8804400))
TabClient.append(C.Consommateur(47, 1,"Orleans","Centre",113224,8491800))
TabClient.append(C.Consommateur(48, 2,"Boulogne-Billancourt","Ile-de-France",113085,8481375))
TabClient.append(C.Consommateur(47, 7,"Mulhouse","Alsace",111156,8336700))
TabClient.append(C.Consommateur(49, 1,"Rouen","Haute-Normandie",110688,8301600))
TabClient.append(C.Consommateur(47, 0,"Cean","Basse-Normandie",109312,8198400))
TabClient.append(C.Consommateur(48, 6,"Nancy","Lorraine",106318,7973850))
TabClient.append(C.Consommateur(48, 2,"Saint-Denis","Ile-de-France",105749,7931175))
TabClient.append(C.Consommateur(44,-93,"Saint-Paul","La Reunion",	103498,7762350))
TabClient.append(C.Consommateur(48, 2,"Montreuil","Ile-de-France",103192,7739400))
TabClient.append(C.Consommateur(48, 2,"Argenteuil","Ile-de-France",102844,7713300))
TabClient.append(C.Consommateur(50, 3,"Roubaix","Nord-Pas-de-Calais",95028,7127100))
TabClient.append(C.Consommateur(51, 2,"Dunkerque","Nord-Pas-de-Calais",92923,6969225))
TabClient.append(C.Consommateur(50, 3,"Tourcoing","Nord-Pas-de-Calais",92389,6929175))
TabClient.append(C.Consommateur(48, 2,"Nanterre","Ile-de-France",89966,6747450))
TabClient.append(C.Consommateur(43, 4,"Avignion","Provence-Alpes-Cote d'Azur",89592,6719400))
TabClient.append(C.Consommateur(48, 2,"Creteil","Ile-de-France",89359,6701925))
TabClient.append(C.Consommateur(46, 0,"Poitiers","Poitou-Charentes",88795,6659625))
TabClient.append(C.Consommateur(14, 61,"Fort-de-France","Martinique",88440,6633000))
TabClient.append(C.Consommateur(48, 2,"Courbevoie","Ile-de-France",86945,6520875))
TabClient.append(C.Consommateur(48, 2,"Versailles","Ile-de-France",86477,6485775))
TabClient.append(C.Consommateur(48, 2,"Vitry-sur-Seine","Ile-de-France",85380,6403500))
TabClient.append(C.Consommateur(48, 2,"Colombes","Ile-de-France",84572,6342900))
TabClient.append(C.Consommateur(43, 0,"Pau","Aquitaine",82763,6207225))
TabClient.append(C.Consommateur(48, 2,"Aulnay-sous-Bois","Ile-de-France",82525,6189375))
TabClient.append(C.Consommateur(48, 2,"Asnieres-sur -Seine","Ile-de-France",81603,6120225))
TabClient.append(C.Consommateur(48, 2,"Rueil-Malmaison","Ile-de-France",79065,5929875))
TabClient.append(C.Consommateur(0,-21.55,"Saint-Pierre","La Reunion",77146,5785950))
TabClient.append(C.Consommateur(43, 7,"Antibes","Provence-Alpes-Cote d'Azur",75553,5666475))
TabClient.append(C.Consommateur(48, 2,"Saint-Maur-des-Fosses","Ile-de-France",75251,5643825))
TabClient.append(C.Consommateur(48, 2,"Champigny-Sur-Marne","Ile-de-France",75090,5631750))
TabClient.append(C.Consommateur(46, -1,"La Rochelle","Poitou-Charentes",74707,5603025))
TabClient.append(C.Consommateur(48, 2,"Aubervilliers","Ile-de-France",74701,5602575))
TabClient.append(C.Consommateur(50, 1,"Calais","Nord-Pas-de-Calais",74336,5575200))
TabClient.append(C.Consommateur(43, 7,"Cannes","Provence-Alpes-Cote d'Azur",73372,5502900))
TabClient.append(C.Consommateur(0,-21.55,"Le Tampon","La Reunion",72658,5449350))
TabClient.append(C.Consommateur(43, 3,"Beziers","Languedoc-Roussillon",70957,5321775))
TabClient.append(C.Consommateur(48, 7,"Colmar","Alsace",67214,5041050))
TabClient.append(C.Consommateur(47, 2,"Bourges","Centre",66786,5008950))
TabClient.append(C.Consommateur(48, 2,"Drancy","Ile-de-France",66670,5000250))
TabClient.append(C.Consommateur(44, 0,"Merignac","Aquitaine",66488,4986600))
TabClient.append(C.Consommateur(47, -2,"Saint-Nazaire","Pays de la Loire",66348,4976100))
TabClient.append(C.Consommateur(44, 4,"Valence","Rhone-Alpes",64367,4827525))
TabClient.append(C.Consommateur(41, 8,"Ajaccio","Corse",64306,4822950))
TabClient.append(C.Consommateur(48, 2,"Issy-les-Moulineaux","Ile-de-France",64027,4802025))
TabClient.append(C.Consommateur(50, 3,"Villeneuve-d\'Ascq","Nord-Pas-de-Calais",63844,4788300))
TabClient.append(C.Consommateur(48, 2,"Levallois-Perret","Ile-de-France",63436,4757700))
TabClient.append(C.Consommateur(48, 2,"Noisy-le-Grand","Ile-de-France",63405,4755375))
TabClient.append(C.Consommateur(47, -4,"Quimper","Bretagne",63387,4754025))
TabClient.append(C.Consommateur(43, 5,"La Seyne-sur-Mer","Provence-Alpes-Cote d'Azur",61514,4613550))
TabClient.append(C.Consommateur(48, 2,"Antony","Ile-de-France",61393,4604475))
TabClient.append(C.Consommateur(48, 4,"Troyes","Champagne-Ardenne",61188,4589100))
TabClient.append(C.Consommateur(48, 2,"Neuilly-sur-Seine","Ile-de-France",60501,4537575))
TabClient.append(C.Consommateur(48, 2,"Sarcelles","Ile-de-France",59421,4456575))
TabClient.append(C.Consommateur(16,-61,"Les Abymes","Guadeloupe",58836,4412700))
TabClient.append(C.Consommateur(45, 4,"Venissieux","Rhone-Alpes",58643,4398225))
TabClient.append(C.Consommateur(48, 2,"Clichy","Ile-de-France",58200,4365000))
TabClient.append(C.Consommateur(47, -3,"Lorient","Bretagne",57812,4335900))
TabClient.append(C.Consommateur(44, 0,"Pessac","Aquitaine",57593,4319475))
TabClient.append(C.Consommateur(48, 2,"Ivry-sur-Seine","Ile-de-France",57254,4294050))
TabClient.append(C.Consommateur(49, 2,"Cergy","Ile-de-France",57247,4293525))
TabClient.append(C.Consommateur(47, 5,"Cayenne","Guyane francaise",57047,4278525))
TabClient.append(C.Consommateur(46, 0,"Niort","Poitou-Charentes",56878,4265850))
TabClient.append(C.Consommateur(45, 5,"Chambery","Rhone-Alpes",56476,4235700))
TabClient.append(C.Consommateur(44, 1,"Montauban","Midi-Pyrenees",56126,4209450))
TabClient.append(C.Consommateur(49, 3,"Saint-Quentin","Picardie",55971,4197825))
TabClient.append(C.Consommateur(48, 2,"Vilejuif","Ile-de-France",55250,4143750))
TabClient.append(C.Consommateur(43, 6,"Hyeres","Provence-Alpes-Cote d'Azur",54686,4101450))
TabClient.append(C.Consommateur(49, 2,"Beauvais","Picardie",54461,4084575))
TabClient.append(C.Consommateur(47, 0,"Cholet","Pays de la Loire",54121,4059075))
TabClient.append(C.Consommateur(48, 2,"Epinay-sur-Seine","Ile-de-France",53577,4018275))
TabClient.append(C.Consommateur(48, 2,"Bondy","Ile-de-France",53448,4008600))
TabClient.append(C.Consommateur(48, 2,"Fontenay-sous-Bois","Ile-de-France",53258,3994350))
TabClient.append(C.Consommateur(43, 6,"Arles","Provence-Alpes-Cote d'Azur",52979,3973425))
TabClient.append(C.Consommateur(0,-20.55,"Saint-Andre","La Reunion",52939,3970425))
TabClient.append(C.Consommateur(47, -2,"Vannes","Bretagne",52683,3951225))
TabClient.append(C.Consommateur(48, 2,"Chelles","Ile-de-France",52636,3947700))
TabClient.append(C.Consommateur(48, 2,"Maisons-Alfort","Ile-de-France",52619,3946425))
TabClient.append(C.Consommateur(48, 2,"Clamart","Ile-de-France",52569,3942675))
TabClient.append(C.Consommateur(48, 2,"Evry","Ile-de-France",52403,3930225))
TabClient.append(C.Consommateur(46, -1,"La Roche-sur-Yon","Pays de la Loire",52234,3917550))
TabClient.append(C.Consommateur(43, 6,"Frejus","Provence-Alpes-Cote d'Azur",52203,3915225))
TabClient.append(C.Consommateur(48, 2,"Pantin","Ile-de-France",52161,3912075))
TabClient.append(C.Consommateur(43, 6,"Grasse","Provence-Alpes-Cote d'Azur",52019,3901425))
TabClient.append(C.Consommateur(38, -90,"Saint-Louis","La Reunion",51460,3859500))
TabClient.append(C.Consommateur(48, 2,"Sartrouville","Ile-de-France",51459,3859425))
TabClient.append(C.Consommateur(43, 3,"Narbonne","Languedoc-Roussillon",51227,3842025))
TabClient.append(C.Consommateur(49, 1,"Evreux","Haute-Normandie",51193,3839475))
TabClient.append(C.Consommateur(47, 0,"Laval","Pays de la Loire",51182,3838650))
TabClient.append(C.Consommateur(48, 2,"Le Blanc-Mesnil","Ile-de-France",51106,3832950))
TabClient.append(C.Consommateur(45, 6,"Annecy","Rhone-Alpes",50254,3769050))
TabClient.append(C.Consommateur(47, 6,"Belfort","Franche-Comte",50199,3764925))
TabClient.append(C.Consommateur(48, 2,"Sevran","Ile-de-France",50021,3751575))

""" Test Unitaire"""
F.distance(TabClient[0],TabClient[1]) 
"""F.distance OK"""
F.findCriticalClient(TabProd[0],TabClient)

"""generation des set Personnalises"""
T1=F.generateSetPerso(TabProd,TabClient)
print("Sets generes\n")
T2=F.linearRelaxation(T1, TabClient)
print("Fin relaxation lineaire")

T3=F.repairingFinal(T1,F.decisionToPickSet(T2), TabClient)
print(T2)
T3=F.repairingFinal(T1,F.decisionToPickSet(T2), TabClient)

print("Solution de la relaxation lineaire initiale\n")
print(T2)
print("Choix en fonction des probabilite allouee avec la rel. Lin\n")
T4=F.decisionToPickSet(T2)
print(T4)
print("Choix 'repare', tous les clients sont couverts\n")
T5=F.decisionToPickSet(T3)
print(T5)

acc=0
for i in range(len(T2)):
    if (T5[i]!=T4[i]):
        acc+=1

print("Nombre de choix repare:")
print(acc)
print("Nombre de Set envisages:")
print(len(T5))



for i in T3:
    if (T3[i]==1):
        print(T1[i].producteur.name)
        for j in range(len(T1[i].TabClient)):
            print(T1[i].TabClient[j].name)
            print(T1[i].TabClient[j].region)
